<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">

    <style>
        thead tr th {
            text-align: center !important;
            font-weight: bold !important;
        }

        tr td {
            text-align: center !important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="test-table-reload-btn layui-col-sm-offset3">
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">注册时间：</div>
                                    <div class="layui-col-sm7">
                                        <input class="layui-input" name="queryTime" id="laydate-cn" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">用户昵称：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="nickName" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">用户账号：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="phone" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-sm3">
                                    <button class="layui-btn layuiadmin-btn-list" lay-submit
                                            lay-filter="LAY-app-contlist-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                                    </button>
                                </div>
                            </div>
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">真实姓名：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="realName" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">用户级别：</div>
                                    <div class="layui-col-sm7">
                                        <select name="levelid" class="select">
                                            <option value="">全部</option>
                                            <c:forEach items="${levelList}" var="lev">
                                                <option value="${lev.id}">${lev.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-table" lay-filter="customer-table" id="customer-table"></table>
                    <script type="text/html" id="table-operate">
                        <div class="layui-btn-container">
<%--                            <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="myTeam"--%>
<%--                               data-flag="1">我的团队</a>--%>
                            <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="editCustomer"
                               data-flag="1">修改资料</a>
                            {{# if(d.status == 1){ }}
                            <a class="layui-btn layui-btn-sm layui-btn-primary" lay-event="updateThis"
                               data-status="0" style="color: red">冻结</a>
                            {{# }}}
                            {{# if(d.status == 0){ }}
                            <a class="layui-btn layui-btn-sm layui-btn-primary" lay-event="updateThis"
                               data-status="1">解冻</a>
                            {{# }}}
                            <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="updatePayword" data-flag="1">重置交易密码</a>
                            <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="updatePassword" data-flag="2">重置登录密码</a>
                            <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="adjustThis"
                               data-flag="3">调整等级</a>
                            <a class="layui-btn layui-btn-sm" lay-event="money">金额明细</a>
                            <a class="layui-btn layui-btn-sm" lay-event="point">创业分明细</a>
                            <%--                            <a class="layui-btn layui-btn-sm" lay-event="share">共享值明细</a>--%>
                            <%--                            <a class="layui-btn layui-btn-sm" lay-event="donate">贡献值明细</a>--%>
                            {{# if(${canShow}){ }}
                            <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="updateParent">修改上级</a>
                            {{# }}}
                            <%--                            <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="remarkThis">备注</a>--%>
                            {{# if(d.directNum > 0){ }}
                            <a class="layui-btn layui-btn-sm layui-btn-primary" lay-event="directCustomer">直推会员</a>
                            {{# }}}
                            {{# if(d.indirectNum > 0){ }}
                            <a class="layui-btn layui-btn-sm layui-btn-primary" lay-event="indirectCustomer">间推会员</a>
                            {{# }}}
                        </div>
                    </script>
                    <script type="text/html" id="index">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="status">
                        {{#  if(d.status == 1){ }}
                        <span class="layui-badge layui-bg-green">正常</span>
                        {{# }else{ }}
                        <span class="layui-badge">冻结</span>
                        {{# }}}
                    </script>
                    <script type="text/html" id="money">
                        <span style="color: red">{{d.account.money.toFixed(2)}}</span>
                    </script>
                    <script type="text/html" id="point">
                        {{d.account.point.toFixed(2)}}
                    </script>
                </div>
            </div>
        </div>
    </div>


</div>

<script src="/layuiadmin/layui/layui.js"></script>

<script>

    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table', 'laydate'], function () {
        var form = layui.form, table = layui.table, $ = layui.$, laydate = layui.laydate;

        laydate.render({
            elem: '#laydate-cn',
            range: '~'
        });

        table.render({
            elem: '#customer-table',
            url: '/customer/queryCustomerList',
            page: true,
            request: {
                pageName: 'current',
                limitName: 'size'
            },
            cols: [[
                {field: 'id', title: '序号', width: 80, fixed: 'left', templet: '#index'},
                {field: 'nickName', title: '昵称', minWidth: 150, fixed: 'left'},
                {field: 'login', title: '账号', minWidth: 120},
                {field: 'levelName', title: '等级', minWidth: 100},
                {field: 'parentName', title: '推荐人', minWidth: 120, templet: '#need'},
                {field: 'directNum', title: '直推数', minWidth: 90, sort: true},
                {field: 'indirectNum', title: '间推数', minWidth: 90, sort: true},
                // {field: 'normalNum', title: '普通会员数', minWidth: 90, sort: true},
                // {field: 'pioneerNum', title: '创业会员数', minWidth: 90, sort: true},
                {field: 'money', title: '剩余金额', minWidth: 100, sort: true, templet: '#money'},
                {field: 'point', title: '剩余创业分', minWidth: 100, sort: true, templet: '#point'},
                {
                    field: 'account.freezeMoney',
                    title: '冻结金额',
                    minWidth: 100,
                    sort: true,
                    templet: "<div>{{d.account.freezeMoney}}</div>"
                },
                {field: 'channelName', title: '用户来源', minWidth: 100},
                {field: 'realName', title: '真实姓名', minWidth: 100},
                {field: 'addressEx', title: '地址', minWidth: 100},
                // {field: 'remarkname', title: '平台备注', minWidth: 100},
                {field: 'status', title: '状态', minWidth: 80, templet: '#status'},
                {
                    field: 'createtime', title: '注册时间', minWidth: 170, sort: true,
                    templet: "<div>{{layui.util.toDateString(d.createtime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                },
                {width: 120, title: '操作', align: 'center', fixed: 'right', toolbar: '#table-operate'}
            ]]
        });

        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('customer-table', {
                where: field
            });
        });

        var active = {
            myTeam: function (id) {
                layer.open({
                    title: '我的团队',
                    type: 2,
                    area: ['850px', '400px'],
                    content: '/customer/customerTeam?cid=' + id
                });
            },
            //修改资料
            editCustomer: function (id) {
                layer.open({
                    title: '修改用户资料',
                    type: 2,
                    area: ['850px', '400px'],
                    content: '/customer/customerEdit?cid=' + id
                });
            },
            //冻结、解除
            updateThis: function (id, status, url) {
                layer.confirm('确定操作吗？', function () {
                    $(".layui-layer-btn0").attr("disabled", true);
                    $(".layui-btn").attr("disabled", true);
                    $.ajax({
                        url: url,
                        data: {'id': id, "status": status},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('customer-table');
                                }, 1000)
                            } else {
                                $(".layui-layer-btn0").attr("disabled", false);
                                $(".layui-btn").attr("disabled", false);
                                layer.msg(data.desc, {icon: 2});
                            }
                        }
                    })
                });
            },
            //重置密码
            updatePassword: function (id, flag, url) {
                layer.confirm("确定要重置吗？重置后密码为'888888'", function () {
                    $(".layui-layer-btn0").attr("disabled", true);
                    $(".layui-btn").attr("disabled", true);
                    $.ajax({
                        url: url,
                        data: {'id': id, "type": flag},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('customer-table');
                                }, 1000)
                            } else {
                                $(".layui-layer-btn0").attr("disabled", false);
                                $(".layui-btn").attr("disabled", false);
                                layer.msg(data.desc, {icon: 2});
                            }
                        }
                    })
                });
            },
            //等级调整
            adjustThis: function (id) {
                layer.open({
                    title: '调整用户等级',
                    type: 2,
                    area: ['400px', '300px'],
                    content: '/customer/customerAdjust?cid=' + id
                });
            },
            //平台备注
            remarkThis: function (id) {
                layer.open({
                    title: '备注',
                    type: 2,
                    area: ['400px', '300px'],
                    content: '/customer/customerRemark?cid=' + id
                });
            },
            // 账户明细
            showThis: function (id, url) {
                window.location.href = url + "?cid=" + id;
            },
            //直推间推会员
            directCustomer: function (flag, id, url) {
                window.location.href = url + "?&flag=" + flag + "&parentid=" + id;
            }
        };

        table.on('tool(customer-table)', function (obj) {
            var data = obj.data;
            var id = data.id;
            if (obj.event === 'updateThis') {
                var type = 'updateThis';
                var status = $(this).data('status');
                var url = "/customer/handleCustomerStatus";
                active[type] && active[type].call(this, id, status, url);
            } else if (obj.event === 'updatePayword') {
                var type = 'updatePassword';
                var flag = 1;
                var url = "/customer/handleCustomerPassword";
                active[type] && active[type].call(this, id, flag, url);
            } else if (obj.event === 'updatePassword') {
                var type = 'updatePassword';
                var flag = 2;
                var url = "/customer/handleCustomerPassword";
                active[type] && active[type].call(this, id, flag, url);
            } else if (obj.event === 'adjustThis') {
                var type = 'adjustThis';
                active[type] && active[type].call(this, id);
            } else if (obj.event === 'editCustomer') {
                var type = 'editCustomer';
                active[type] && active[type].call(this, id);
            } else if (obj.event === 'myTeam') {
                var type = 'myTeam';
                active[type] && active[type].call(this, id);
            } else if (obj.event === 'remarkThis') {
                var type = 'remarkThis';
                active[type] && active[type].call(this, id);
            } else if (obj.event === 'directCustomer') {
                var type = 'directCustomer';
                var url = "/customer/directOrIndirectCustomer";
                var flag = 1;
                active[type] && active[type].call(this, flag, id, url);
            } else if (obj.event === 'indirectCustomer') {
                var type = 'directCustomer';
                url = '/customer/directOrIndirectCustomer';
                var flag = 2;
                active[type] && active[type].call(this, flag, id, url);
            } else if (obj.event === 'money') {
                var type = 'showThis';
                var url = "/customer/customerMoney";
                active[type] && active[type].call(this, id, url);
            } else if (obj.event === 'point') {
                var type = 'showThis';
                url = '/customer/customerPoint';
                active[type] && active[type].call(this, id, url);
            } else if (obj.event === 'donate') {
                var type = 'showThis';
                url = '/customer/customerDonate';
                active[type] && active[type].call(this, id, url);
            } else if (obj.event === 'share') {
                var type = 'showThis';
                url = '/customer/customerShare';
                active[type] && active[type].call(this, id, url);
            } else if (obj.event === 'updateParent') {
                layer.open({
                    type: 2
                    , title: '编辑推荐人'
                    , content: '/customer/parentUpdate?cid=' + data.id
                    , maxmin: true
                    , area: ['500px', '550px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        });

        //缓存当前操作的是哪个表格的哪个tr的哪个td
        $(document).off('mousedown', '.layui-table-grid-down').on('mousedown', '.layui-table-grid-down', function (event) {
            //直接记录td的jquery对象
            table._tableTrCurrr = $(this).closest('td');
        });

        //给弹出的详情里面的按钮添加监听级联的触发原始table的按钮的点击事件
        $(document).off('click', '.layui-table-tips-main [lay-event]').on('click', '.layui-table-tips-main [lay-event]', function (event) {
            var elem = $(this);
            var tableTrCurrr = table._tableTrCurrr;
            if (!tableTrCurrr) {
                return;
            }
            var layerIndex = elem.closest('.layui-table-tips').attr('times');
            layer.close(layerIndex);
            table._tableTrCurrr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
        });
    });
</script>
</body>
</html>